package com.wxz.ldap.p2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.naming.InvalidNameException;
import java.util.List;

/**
 * @author xianzhang.wang
 * @Description
 * @date 2018/7/12
 */
@RestController
public class TestController {

    @Autowired
    private OdmPersonRepo odmPersonRepo;

    @GetMapping("/test/cn/{cn}")
    public List<User> findByCn(@PathVariable("cn") String cn){
        List<User> persons = odmPersonRepo.findByCn(cn);
        return persons;
    }

    @GetMapping("/test/all")
    public List<User> findAll() throws InvalidNameException {
        List<User> persons = odmPersonRepo.findList();
        return persons;
    }

    @GetMapping("/test/ou/{ou}")
    public List<User> findByOu(@PathVariable("ou") String ou) throws InvalidNameException {
        List<User> persons = odmPersonRepo.findByOu(ou);
        return persons;
    }

    @PatchMapping("/test/user/odm")
    public void modifyUser() throws InvalidNameException {
        odmPersonRepo.updateByODM();
    }

    @PostMapping("/test/user/cn")
    public void createUserByCn() throws InvalidNameException {
        odmPersonRepo.createUserByCn();
    }

    @PostMapping("/test/user/sn")
    public void createUserBySn() throws InvalidNameException {
        odmPersonRepo.createUserBySn();
    }

    @DeleteMapping("/test/user")
    public void deleteByDn(){
        odmPersonRepo.deleteUser();
    }
}
